#ifndef LOGINACCOUNT_H
#define	LOGINACCOUNT_H

using namespace std;

struct date_t{
    string day;
    string month;
    int year;
};

string getDate(date_t date){
    string temp;
    stringstream ss;
    ss << date.day << date.month << date.year;
    
    return ss.str();
}

class LoginAccount{
private:
    int id;
    string password;
    string userType;
    date_t date;
public:
    LoginAccount(){
        id = 0;
        password = "";
        userType = "";
        date.day = "31";
        date.month = "Dec";
        date.year = 2012;
    }
    
    LoginAccount(int userID, string passwd){
        id = userID;
        password = passwd;
    }
    
    bool checkCred(){        
        bool CredOK = false;
        string getHash, getStatus, getAccType, userIDstr, zSQLstr;
        stringstream ss;
        
        Database *db;
        db = new Database("test.db");
        
        ss << "SELECT * FROM user where id = " << id << ";";
        zSQLstr = ss.str();
        
        char* zSQL = (char*)zSQLstr.c_str();
        
        vector<vector<string> > result = db->query(zSQL);
        
        for(vector<vector<string> >::iterator it = result.begin(); it < result.end(); ++it){
            vector<string> row = *it;
            getHash = row.at(1);
            getAccType = row.at(4);
            getStatus = row.at(5);
        }
        
        if(getHash.length() != 0){
            if(password == getHash){
                if(getStatus == "Active"){
                    userType = getAccType;
                    CredOK = true;
                }else{
                    cout << "User account is inactive" << endl;
                }
            }else{
                cout << "Login Credentials are incorrect" << endl;
            }
        }else{
            cout << "No user found" << endl;
        }
        
        db->close();
        
        return CredOK;
    }
    
    void setExpDate(string mday, string mon, int yr){
        date.day = mday;
        date.month = mon;
        date.year = yr;
        
    }
        
    int getID() {return id;}
    
    string getPasswd() {return password;}
    
    string getUsrType() {return userType;}
    
    date_t getDate() {return date;}
};

#endif	/* LOGINACCOUNT_H */

